#include "app_encoderTim.h"

static int32_t count;



void TIM3_IRQHandler(){
  if (TIM_Interrupt_Status_Get(TIM3, TIM_INT_CC1) == SET)
  {
    if(CHA_READ() == 1)
    {
      count++;
    }else{
      count--;
    }
      
    TIM_Interrupt_Status_Clear(TIM3, TIM_INT_CC1);
  }else if (TIM_Interrupt_Status_Get(TIM3, TIM_INT_CC2) == SET){
    
    if(CHA_READ() == 0)
    {
      count++;
    }else{
      count--;
    }
    TIM_Interrupt_Status_Clear(TIM3, TIM_INT_CC2);
  }
}

int32_t encoder_Get(void)
{
  int32_t temp = count;
  count = 0;
  return temp;
}

void encoder_Init(void)
{
  count = -100;
}
